package utility;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

public class PropertyManager {
	private static final String configFilePath = "/app.properties";
	private static Properties properties;

	private PropertyManager() { /* not to be called	*/ }

	@SuppressWarnings("unchecked")
	public static <T> T GetConfigValue(String key) throws IOException
	{
		if(properties == null)
			LoadProperties(configFilePath);
		return (T) properties.get(key);
	}

	private static void LoadProperties(String configFilePath) throws IOException
	{
		Properties myProps = new Properties();
		InputStream myInputStream = PropertyManager.class.getResourceAsStream(configFilePath);
		myProps.load(myInputStream);
		properties = myProps;
	}

	public static void main(String[] args) {
		try {
			PropertiesConfiguration config = new PropertiesConfiguration("app.properties");

			System.out.println(config.getList("testNodeAddress"));

			System.out.println(config.getList("registryAddress"));
		} catch (ConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
